<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta content="telephone=no" name="format-detection" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
	<title>打开或下载应用</title>

	<!--<script src="assets/plugins/jquery-1.8.3.min.js" type="text/javascript"></script>-->
</head>
<body>

<a id="vlink" onClick="try_to_open_app()" style="display:none"></a>
<script>
    var browser={
        versions:function(){
            var u = navigator.userAgent, app = navigator.appVersion;
            return {
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
                iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
            };
        }()
    }
    var iOS_URL = "myapp://www.test.com_uid=123";
    var Android_URL = "myapp://www.test.com/openwith?uid=123";
    var mtUrl = "http://www.test.com/download";
    function open_link() {
        window.location=mtUrl;
    }
    function try_to_open_app() {
        setTimeout('open_link()', 500);
    }
    //IOS
    if(browser.versions.iPhone){
        document.getElementById("vlink").setAttribute("href",iOS_URL);
        document.getElementById("vlink").click();
    }
    //Android
    else if(browser.versions.android){
        document.getElementById("vlink").setAttribute("href",Android_URL);
        document.getElementById("vlink").click();
    }

    else{
        open_link();
    }
</script>
</body>
</html>